package com.example.hcd.tool;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.hcd.functionactivity.ShowPictureList;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/11/26.
 */
public class NoticeDetailView extends LinearLayout implements View.OnClickListener {

    private ArrayList<String> mTextData, mImgData;
    private Context mContext;
    private int num = 0;


    // private int mImgSize = 0;

    public NoticeDetailView(Context context, ArrayList<String> Textdata, ArrayList<String> ImgData) {
        super(context);
        this.setOrientation(LinearLayout.VERTICAL);
        this.mTextData = Textdata;
        this.mImgData = ImgData;
        this.mContext = context;
        init();
    }


    private void init() {
        for (int i = 0; i < mTextData.size(); i++) {


            TextView textView = new TextView(mContext);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            textView.setTextColor(Color.parseColor("#727272"));
            textView.setText(mTextData.get(i));
            LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lllp.setMargins(5, 5, 5, 5);
            this.addView(textView, lllp);


        }
        for (int i = 0; i < mImgData.size(); i++) {
            final ImageView imageView = new ImageView(mContext);
            final int pos = i;
            imageView.post(new Runnable(){
                @Override
                public void run() {
                    ImageLoader.getInstance().displayImage(mImgData.get(pos), imageView);
                }
            });
//            ImageLoader.getInstance().displayImage(mImgData.get(i), imageView);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setAdjustViewBounds(true);
//            imageView.setBackgroundColor(Color.parseColor("#505050"));
            LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lllp.setMargins(5, 5, 5, 5);
            this.addView(imageView, lllp);

            imageView.setTag(num);
            num++;
            imageView.setOnClickListener(this);


        }

    }

    @Override
    public void onClick(final View v) {
        switch (v.getId()) {
            default:
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                intent.putStringArrayListExtra("PICK_PATH_LIST", mImgData);
                intent.putExtra("IS_BENDI", false);
                intent.setClass(mContext, ShowPictureList.class);
                intent.putExtra("MOREN_INDEX", (Integer) v.getTag());

                intent.putExtras(bundle);

                mContext.startActivity(intent);
                break;
        }
    }
}
